import request from '@/utils/request'
import Qs from 'qs'

export function login(data) {
  return request({
    url: '/platform/security/login',
    method: 'post',
    data
  })
}

export function getInfo() {
  return request({
    url: '/platform/security/account/info',
    method: 'get'
  })
}

/**
 * 获取当前用户菜单信息
 *
 * @export
 * @returns
 */
export function getMenus() {
  return request.get('/platform/security/account/actions')
}

/**
 *
 * 获取当前账号角色信息
 * @export
 * @returns
 */
export function getRoles() {
  return request.get('/platform/security/account/roles')
}

export function logout() {
  return request({
    url: '/user/logout',
    method: 'post'
  })
}

/**
 * 分页查询用户信息
 * @param {*} params 
 * @param {*} data 
 */
export function userQuery(params) {
  return request.get(`/platform/security/account/query?${Qs.stringify(params)}`)
}

/**
 * 添加账号
 * @param {*} data 
 */
export function userAdd(data) {
  return request.post('/platform/security/accounts', data)
}

export function userEdit(data) {
  return request.patch(`/platform/security/account/${data.accountId}/info`, data)
}

export function userDetail(accountId) {
  return request.get(`/platform/security/account/${accountId}/info`)
}

/**
 * 禁用账号
 * @param {*} id 
 */
export function disableUser(id) {
  return request.patch(`/platform/security/account/${id}/disable`)
}

/**
 * 启用账号
 * @param {} id 
 */
export function enableUser(id) {
  return request.patch(`/platform/security/account/${id}/enable`)
}

/**
 * 获取用户权限
 * @param {*} id 
 */
export function getActionByUserId(id) {
  return request.get(`/platform/security/account/${id}/actions`)
}

/**
 * 重置密码
 * @param {*} id 
 */
export function resetPassword(id) {
  return request.patch(`/platform/security/account/${id}/password/reset`)
}

/**
 * 获取当前用户权限列表
 */
export function getCurrentAction() {
  return request.get(`/platform/security/account/actions/tree`)
}

/**
 * 获取当前用户信息
 */
export function getCurrentUserInfo() {
  return request.get(`/platform/security/account/info`)
}

/**
 * 修改密码
 */
export function editPassword(data) {
  return request.patch(`/platform/security/account/password`, data)
}
